<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<!DOCTYPE html>
<html>
<head>
    <title>合同管理</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>  
    <!--[if lt IE 9]>
        <script src="${ctx}/lib/js/html5shiv.min.js"></script>
        <script src="${ctx}/lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">		
    <section class="content-header">
        <h1>合同管理</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">合同管理</a></li>
            <li class="active"><a href="#">合同查看</a></li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class="form-inline">
                    <div class="form-group form-group-xs">
						<label>所属项目：</label> 
						<select class='form-control' id="projectId"
							style="width: 150px;">
							<option value="">请选择</option>
							<c:forEach items="${projectList}" var="project">
								<option value="${project.projId }">${project.name}</option>
							</c:forEach>
						</select>
					</div>
                    <div class="form-group form-group-xs">
                        <label for="contractTitle">合同名称：</label>
                        <input class="form-control" type="text" id="contractTitle" placeholder="合同名称" maxlength="100" />
                    </div>
                  
					<div class="form-group form-group-xs">
						<label>状态：</label> <select class='form-control' id="status"
							style="width: 100px;">
							<option value="">请选择</option>
							<option value="1">启用</option>
							<option value="0">停用</option>
						</select>
					</div>
					<div class="form-group form-group-xs">
						<label>审核状态：</label> <select class='form-control' id="auditStatus"
							style="width: 100px;">
							<option value="">请选择</option>
							<option value="0">新建</option>
							<option value="1">提交</option>
							<option value="2">审核通过</option>
							<option value="3">审核不通过</option>
						</select>
					</div>
                    <button type="button" class="btn btn-success btn-sm" onclick="search();">查&nbsp;询</button>
                </div>
            </div>
        </div>
        
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        
        <div class=" box box-warning bottongroup">
             <a href="javascript:addContract()" class="btn btn-default btn-sm">新&nbsp;增</a>
              <a href="javascript:changeAuditStatus(1)" class="btn btn-default btn-sm">提&nbsp;交</a>
             <a href="javascript:changeStatus(1)" class="btn btn-default btn-sm">启&nbsp;用</a>
             <a href="javascript:changeStatus(0)" class="btn btn-default btn-sm">停&nbsp;用</a>
        </div>
 <!-- 选择合同模板 -->
  <div class="modal fade" id="selectcomp" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header bg-primary">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h5 class="modal-title" id="exampleModalLabel">选择合同模板</h5>
                    </div>
                    <div class="modal-body" style="background-color:#ecf0f5">
                      <form >
                         <div class="box box-success">
                           <div class="box-body">
                             <div class="form-inline">
                             	<div class="form-group form-group-xs">
                                                                                                    模板编码： <input class="form-control" type="text" id="contractModelCode" placeholder="模板编码" />
                   				</div>
                                <div class="form-group form-group-xs">
                         		   	    合同模板名称：<input class="form-control" type="text" id="contractModelName" placeholder="合同模板名称" />
                                </div>
                                <button type="button" class="btn btn-success btn-sm" onclick="contractModelSearch()">查&nbsp;询</button>
                             </div>
                           </div>
                         </div>
                         <div class="form-group form-group-xs">
                                <table class="jqgrid col-sm-1" id="gridlistModel"></table>
       						    <div id="gridpageModel"></div>
                        </div>
                      </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" onclick="chooseModel();" class="btn btn-primary btn-sm">选&nbsp;择</button>
                        <button type="button" onclick="cleandata();" class="btn btn-danger btn-sm" data-dismiss="modal">取&nbsp;消</button>
                    </div>
                </div>
            </div>
      </div>
<!-- 选择合同模板 -->
    </section>
     <%@ include file="/WEB-INF/component/commonJS.jsp" %>  
    <script type="text/javascript">
        function chooseModel(){
           var Id = $("#gridlistModel").jqGrid('getGridParam', 'selrow');
  	       if (Id == null) {
  	    	   $.HN.message.alert('请至少选一行！', '提示信息', 'error');
  	           return;
  	       }
  	       var rowdata = $("#gridlistModel").jqGrid('getRowData', Id);
  	       document.location.href = "${ctx}/contractSC/toBidContractEditSC.html?contractModelId="+rowdata.contractModelId+"&opType=0";
        }
        function addContract(){
        	 $('#selectcomp').modal({
     			keyboard : true
     		});
        }
    	function changeStatus(status) {
    		var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
    		if (rowIds.length <= 0) {
    			$.HN.message.alert("请选择要操作的行！", "提示消息", "warn");
    			return;
    		}
    		var str = "";
			var overId = "";
			var message = "停用";
			if(status == 1){
				message = "启用";
			}
			for (var i = 0; i < rowIds.length; i++) {
				str += rowIds[i] + ",";
				var rowdata = $("#gridlist").jqGrid(
						'getRowData', rowIds[i]);
				overId += rowdata.contractId + ",";
			}
			if (str.length > 0) {
				str = str.substring(0, str.length - 1);
			}
			$.HN.message.confirm("确定"+message+"吗？", '', '').on(function (e) {
                if (e) {
    		$.post("changeStatusSC.html", {
    			"overId" : overId,
    			"status" : status
    		}, function(result) {
    			if (result.success) {
    				var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
    				search(curpage);
    				$.HN.message.alert("保存成功！", "消息", "success");
    			} else {
    				$.HN.message.alert("保存失败！", "消息", "error");
    			}
    		}, "json")
                }
    		});
    	}
    	function changeAuditStatus(auditStatus){
    		var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
    		if (rowIds.length <= 0) {
    			$.HN.message.alert("请选择要操作的行！", "提示消息", "warn");
    			return;
    		}
    		var str="";
			var overId = "";
			for (var i = 0; i < rowIds.length; i++) {
				str += rowIds[i] + ",";
				var rowdata = $("#gridlist").jqGrid(
						'getRowData', rowIds[i]);
				overId += rowdata.contractId + ",";
			}
			if (str.length > 0) {
				str = str.substring(0, str.length - 1);
			}
			$.HN.message.confirm("确定提交吗？", '', '').on(function (e) {
                if (e) {
    		$.post("changeAuditStatusSC.html", {
    			"overId" : overId,
    			"auditStatus" : auditStatus
    		}, function(result) {
    			if (result.success) {
    				var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
    				search(curpage);
    				$.HN.message.alert(result.msg, "消息", "success");
    			} else {
    				$.HN.message.alert(result.msg, "消息", "warn");
    			}
    		}, "json")
                }
    		});
    	}
    	 //合同模板搜索
    	 function contractModelSearch() {
    		   	var contractModelName = $("#contractModelName").val();
    		   	var contractModelCode = $("#contractModelCode").val();
    				$("#gridlistModel").jqGrid('setGridParam',{  
    			        datatype:'json',
    			        postData:{"contractModelName":contractModelName, "contractModelCode":contractModelCode}
    			    }).trigger("reloadGrid"); //重新载入  
    	}
    	 //合同模板选择完成
    	function gridOk(){
    		 var contractModelId = $("#gridlistModel").jqGrid('getGridParam', 'selrow');
    		    if (compId == null) {
    		    	 $.HN.message.alert('请至少选一行！', '提示信息', 'error');
    		         return;
    		     }
    		     var rowdata = $("#gridlistModel").jqGrid('getRowData', contractModelId);
    		     $("#comp").val(rowdata.compName);
    		     $("#selectComp").modal("hide");
    	}
    	
    	function search(page) {
    		var projectId = $.trim($("#projectId").val());
    		var contractTitle = $.trim($("#contractTitle").val());
    		var status = $.trim($("#status").val());
    		var auditStatus = $.trim($("#auditStatus").val())
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:{"projId":projectId, "contractTitle":contractTitle ,"status":status, "auditStatus":auditStatus},
    	        page : (page || 1)
    	    }).trigger("reloadGrid"); //重新载入  
    	}
    
        $(function () {
            $("#gridlist").jqGrid({
                url: "getContractListSC.html",
                mtype: "post",
                datatype: "json",
                autowidth: true,
                shrinkToFit: false,
                height: 270,
                colNames: [
       				'操作',
                    '所属项目',
                    '合同id',
                    '合同编码',
                    '合同标题',
                    '合同甲方',
                    '合同乙方',
                    '签订日期',
                    '审核状态',
                    '审核时间',
                    '状态',
                ],
                colModel: [
					{ name: 'operate', width: 140, align:"center", sortable: false,
						formatter : function(val, opts, rowdata) {
							var str=""
					    	str +=  "<a href='toEditContractSC.html?contractId=" + rowdata.contractId + "&optType=1'>编辑</a>";
								str += "<a href='toBidContractDetailSC.html?contractId=" + rowdata.contractId + "'>详情</a>";
								//str += "<a href='toBidContractLogList.html?contractId=" + rowdata.contractId + "'>维护记录</a>";
					    	return str;
					}},
                    { name: 'projName', width: 160, align:"center", sortable: false},
                    { name: 'contractId', hidden:true, width: 100, align:"center", sortable: false},
                    { name: 'contractCode',hidden:true, width: 120, align:"center", sortable: false},
                    { name: 'contractTitle', width: 160, align:"center", sortable: false },
                    { name: 'contractPartyA', width: 160, align:"center", sortable: false },
                    { name: 'contractPartyB', width: 160, align:"center", sortable: false },
                    { name: 'signupDatetime', width: 140, align:"center", sortable: false },
                    { name: 'auditStatus', width: 60, align: 'center', sortable: false,
                    	formatter : function(val, opts, rowdata) {
                    		var strSta = "";
                    		if(rowdata.auditStatus == 0){
                    			strSta += "新建";
                    		}else if(rowdata.auditStatus == 1){
                    			strSta += "提交";
                    		}else if(rowdata.auditStatus == 2){
                    			strSta += "通过";
                    		}else if(rowdata.auditStatus == 3){
                    			strSta += "不通过";
                    		}
                    		return strSta;
                    	}
                    },
                    { name: 'auditDatetime', width: 160, align:"center", sortable: false },
                    { name: 'status', width: 40, align: 'center', sortable: false,
                    	formatter : function(val, opts, rowdata) {
                    		var strSta = "";
                    		if(rowdata.status == 1){
                    			strSta += "启用";
                    		}else{
                    			strSta += "停用";
                    		}
                    		return strSta;
                    	}
                    }
                    
                ],
                rowNum: 20,
                rowList: [10, 20, 50, 100],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: true, 
                viewrecords: true,
                caption: "合同列表",
                jsonReader: {
                    id: "contractModelId"
                }
            });
            
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            
            //选择合同模板
      $("#gridlistModel").jqGrid({
	       url: "${ctx}/contractModel/getContractModelList.html?status=1",
	       mtype: "POST",
	       datatype: "json",
	       autowidth: true,
	       shrinkToFit: false,
	       height: 255,
	       colNames: ['合同模板id','合同模板编码', '合同模板名称'],
	       colModel: [
                    { name: 'contractModelId',hidden:true, width: 240 , align:"center",sortable: false },
					{ name: 'contractModelCode', width: 240 , align:"center",sortable: false },
					{ name: 'contractModelName', width: 290 , align:"center" ,sortable: false}
	       ],
	       rowNum: 10,
	       rowList: [10, 20, 50,100],
	       rownumbers: true,
	       pager: "#gridpageModel",
	       //multiselect: true, 
	       viewrecords: true,
	       caption: "配送企业选择",
	       jsonReader: {
	           repeatitems: false,
	           id: "ids"
	       }
      });
	})
    </script>
</body>
</html>












